<?php


require 'database.php';

$__qh__=$_POST["qh"];
$__jm__=trim($_POST["jm"]);
$ar=[
    "fUcsQz",
    "rRWpt",
    "pxhiP",
    "dhdAZQ",
    "bLSQCV",
    "ebQeaq",
    "iKppsD",
    "fPEdFk",
    "kSqQeq",
    "lhkbUk"
];

if(!$__qh__){
    return json([
        "code"=>-1    
    ]); 
}

$_issue_=file_get_contents("issue.json");
$_issue_=json_decode($_issue_,1);

$__copyorder__=file_get_contents("copyorder.json");
$__copyorder__=json_decode($__copyorder__,1);

$__qh__=trim(str_replace("期开奖","",$__qh__));

$__p__=0;

if ($_issue_[count($_issue_)-1]["issue"]==$__qh__) $__p__=1;

if($__p__==0){
    return json([
        "code"=>-1
    ]);   
}
// $__jm__=file_get_contents("text.txt");


$_arr_=[];

$__jm__=str_replace("\\","",$__jm__);
// $__jm__=str_replace("\\","",$__jm__);

preg_match_all('/(?!(<span class="sc-19tlabe-0 gVEdcZ"><div class="sc-1508qac-0 ))[a-z A-Z]{6}(?=("><\/div><\/span>))/',$__jm__,$_arr_);

$_arr_=$_arr_[0];

// file_put_contents("abc.txt",json_encode($_arr_,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));

$__tosz__=[];

for ($a = 0; $a < count($_arr_); $a++) {
    for ($b = 0; $b < count($ar); $b++) {
        if( trim($_arr_[$a]) == $ar[$b] ){
            $__tosz__[]=$b+1;
        }

    }
}

$__qhtoar__=[];

for ($i = 0; $i < count($__copyorder__); $i++) {
    if($__copyorder__[$i]["issue"]==$__qh__){
        // $__qhtoar__[]=$__copyorder__[$i];
        
        $treeid=0;
        $j=0;
        $v=0;
        $treeid=$__copyorder__[$i]["tree_id"];
        $j=$__copyorder__[$i]["pid"];
        
        //开奖值(确定赛道)
        $v=$__tosz__[$treeid-1];
        
        $_PP_=0;

        if($v <= 5 && $j==2){
            $__copyorder__[$i]["result"]="yes";

        }elseif($v >= 6 && $j==2){
            $__copyorder__[$i]["result"]="no";
        }
        
        if($v >= 6 && $j==1){
            $__copyorder__[$i]["result"]="yes";

        }elseif($v <= 5 && $j==1){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $v%2!=0 && $j==3){
            $__copyorder__[$i]["result"]="yes";
        }elseif($v%2==0 && $j==3){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $v%2==0 && $j==4 ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $v%2!=0 && $j==4 ){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $treeid==1 && $j == 5 && $__tosz__[0]>$__tosz__[9] ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $treeid==1 && $j == 5 && $__tosz__[0]<$__tosz__[9] ){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $treeid==2 && $j == 5 && $__tosz__[1]>$__tosz__[8] ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $treeid==2 && $j == 5 && $__tosz__[1]<$__tosz__[8] ){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $treeid==3 && $j == 5 && $__tosz__[2]>$__tosz__[7] ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $treeid==3 && $j == 5 && $__tosz__[2]<$__tosz__[7] ){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $treeid==4 && $j == 5 && $__tosz__[3]>$__tosz__[6] ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $treeid==4 && $j == 5 && $__tosz__[3]<$__tosz__[6] ){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $treeid==5 && $j == 5 && $__tosz__[4]>$__tosz__[5] ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $treeid==5 && $j == 5 && $__tosz__[4]<$__tosz__[5] ){
            $__copyorder__[$i]["result"]="no";
        }
        
        
        
        if( $treeid==1 && $j == 6 && $__tosz__[0]<$__tosz__[9] ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $treeid==1 && $j == 6 && $__tosz__[0]>$__tosz__[9] ){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $treeid==2 && $j == 6 && $__tosz__[1]<$__tosz__[8] ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $treeid==2 && $j == 6 && $__tosz__[1]>$__tosz__[8] ){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $treeid==3 && $j == 6 && $__tosz__[2]<$__tosz__[7] ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $treeid==3 && $j == 6 && $__tosz__[2]>$__tosz__[7] ){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $treeid==4 && $j == 6 && $__tosz__[3]<$__tosz__[6] ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $treeid==4 && $j == 6 && $__tosz__[3]>$__tosz__[6] ){
            $__copyorder__[$i]["result"]="no";
        }
        
        if( $treeid==5 && $j == 6 && $__tosz__[4]<$__tosz__[5] ){
            $__copyorder__[$i]["result"]="yes";
        }elseif( $treeid==5 && $j == 6 && $__tosz__[4]>$__tosz__[5] ){
            $__copyorder__[$i]["result"]="no";
        }
        
        if(!$__copyorder__[$i]["result"]){
            $__copyorder__[$i]["result"]="yes";
        }
        
    }
}




$__copyorder__=json_encode($__copyorder__,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
file_put_contents("copyorder.json",$__copyorder__);

return json([
    "code"=>200    
]);



// return json($_arr_[2]);